import 'terms.dart';

final Map<int, Terms> parataxisTermsList = {
  4: Terms.smallJump,
  5: Terms.smallFly,
  8: Terms.elephantStep,
  9: Terms.bigJump,
  10: Terms.bigFly,
  -4: Terms.block,
  16: Terms.superBigJump,
  17: Terms.superBigFly,
  -5: Terms.flySuppress,
  -9: Terms.suppress,
  -10: Terms.suppress,
  -16: Terms.reducingMove,
  -17: Terms.reducingMove
};

/// 并列术语判定
String judgeParataxisTerms(
  ChessStep chessStep, {
  Board? board,
}) {
  // printInfo('进入并列术语判定');
  var parataxisTerms = Terms.none.desc;
  final nonZeroSteps = getNonZeroChessSteps(board!);
  List<ChessStep> selfStepList = [];
  int calculate(s) {
    int ss = 0;
    for (final step in nonZeroSteps) {
      var distance = distanceSquared(chessStep, step.x, step.y);
      if (chessStep.bw != step.bw) {
        distance = -distance;
      }
      // printInfo('distance:$distance');
      if (distance == s) {
        ss = distance;
        if (chessStep.bw == step.bw) {
          selfStepList.add(step);
        }
        break;
      }
    }
    return ss;
  }

  for (int s = 0; s < parataxisTermsList.length; s++) {
    var keyList = parataxisTermsList.keys.toList();
    var valueList = parataxisTermsList.values.toList();
    int key = keyList[s];
    var distance = calculate(key);

    if (distance == key) {
      var terms = valueList[s];
      // printInfo('terms:$terms');
      if (terms == Terms.smallJump) {
        if (selfStepList.isNotEmpty) {
          var step = selfStepList[0];
          chessStep =
              ChessStep(board.getBoardSize() + 1 - step.y, step.x, step.bw);
          // printInfo('chessStep:${'${chessStep.x}...${chessStep.y}'}');
          if (board.airCount(chessStep) == 1) {
            continue;
          }
        }
      }
      parataxisTerms = terms.desc;
      if (parataxisTerms.isNotEmpty) {
        break;
      }
    }
  }
  return parataxisTerms;
}
